package cn.fenglaicaimi.controller;

import cn.fenglaicaimi.base.domain.User;
import cn.fenglaicaimi.base.service.IUserService;
import cn.fenglaicaimi.base.util.AjaxResult;
import cn.fenglaicaimi.base.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {
    @Autowired
    private IUserService userService;

    @RequestMapping("managerLogin")
    @ResponseBody
    public AjaxResult login(User user) {
        AjaxResult result = new AjaxResult();
        User uu = this.userService.get(user);
        if(uu != null){
            result.setMessage("登录成功");
            UserContext.setCurrent(uu);
        }else{
            result.mark("账号或密码错误");
        }
        return result;
    }

    @RequestMapping("index")
    public String mainPage(){
        return "main";
    }

}
